<?php

require_once dirname(__FILE__) . '/../lib/doctor_time_slotGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/doctor_time_slotGeneratorHelper.class.php';

/**
 * doctor_time_slot actions.
 *
 * @package    docplus.co.za
 * @subpackage doctor_time_slot
 * @author     Fox Matuku
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class doctor_time_slotActions extends autoDoctor_time_slotActions {

	public function preExecute() {
		$this->getUser()->setCurrentRoute("doctor_schedule");
		if ($this->getUser()->getType() == "Doctor") {
			$this->doctorId = $this->getUser()->getDoctor()->getId();
		}
		else {
			$this->doctorId = $this->getUser()->getDoctorId();
		}
		DoctorTimeSlotTable::getInstance()->autoGenerateTimeSlotsPlannerByDoctorId($this->doctorId);
		parent::preExecute();
	}

	public function executeNew(sfWebRequest $request) {
		$this->form = $this->configuration->getForm();
		$this->form->setDefault("doctor_id", $this->doctorId);
		$this->doctor_time_slot = $this->form->getObject();
	}

	protected function buildQuery() {
		$query = parent::buildQuery();
		$query->addWhere('a.doctor_id = ?', $this->doctorId);
		return $query;
	}

}
